package gui;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

public class MoHinhTable extends AbstractTableModel {
	private static final long serialVersionUID = 1L;
	
	public ArrayList<ClientInfo> dsClient;
	public String[] header = {"Ten may", "IP", "Port", "dich vu Port"};
	
	public MoHinhTable() {
		dsClient = new ArrayList<ClientInfo>();
	}
	
	public int getColumnCount() {
		return header.length;
	}
	
	public String getColumnName(int col) {
		return header[col];
	}

	public int getRowCount() {
		return dsClient.size();
	}

	public Object getValueAt(int row, int cot) {
		switch(cot) {
			case 0:
				return dsClient.get(row).controlSocket.getInetAddress().getHostName();
			case 1:
				return dsClient.get(row).controlSocket.getInetAddress().getHostAddress();
			case 2:
				return dsClient.get(row).controlSocket.getPort();
			case 3:
				return dsClient.get(row).servicePort;
			default:
				return null;
			
		}
	}

	public void addRow(ClientInfo ci) {
		dsClient.add(ci);
		fireTableRowsInserted(dsClient.size()-1, dsClient.size()-1);
	}
	
	public ClientInfo getRow(int index) {
		return dsClient.get(index);
	}
}
